﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Tomahawk.Runtime.Resources;

namespace Tomahawk.Runtime.Canvas.Sprite
{
    public abstract class Sprite : LoadableResource, ICanvasPrimitive
    {

        /// <summary>
        /// Implement this method in the derived class to render the primitive
        /// </summary>
        public abstract void Render(SpriteBatch spriteBatch);

        /// <summary>
        /// Implement this method in the derived class load the required resources
        /// </summary>
        protected abstract override bool OnLoad(GraphicsDevice graphics, ContentManager contentManager);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sprite"></param>
        public delegate void OnInvalidateRenderBatchDelegate(Sprite sprite);
        
        /// <summary>
        /// 
        /// </summary>
        public event OnInvalidateRenderBatchDelegate OnInvalidateRenderBatch;

        /// <summary>
        /// Screen position where to be painted
        /// </summary>
        public Rectangle DestinationRectangle;

        /// <summary>
        /// Texture coordinates to sample
        /// </summary>
        public Rectangle SourceRectangle;

        /// <summary>
        /// Color tint
        /// </summary>
        public Color Color = Color.White;

        /// <summary>
        /// Sprite Effect
        /// </summary>
        public SpriteEffects Effect = SpriteEffects.None;

        /// <summary>
        /// Depth
        /// </summary>
        private float depth = 0.0f;
        public float Depth
        {
            get { return this.depth; }
            set
            {
                if (OnInvalidateRenderBatch != null && (this.depth != value))
                {
                    OnInvalidateRenderBatch(this);
                }
                this.depth = value;
            }
        }

        /// <summary>
        /// Determine when the primitive is rendered or not
        /// </summary>
        private bool visible = true;

        /// <summary>
        /// Determine when the primitive is rendered or not
        /// </summary>
        public bool Visible
        {
            get { return this.visible; }
            set { this.visible = value; }
        }

        /// <summary>
        /// Effect channel used to render this sprite
        /// </summary>
        private string effectChannel = "Default";

        /// <summary>
        /// Effect channel used to render this sprite
        /// </summary>
        public string EffectChannel
        {
            get { return this.effectChannel; }
            set 
            {
                if (OnInvalidateRenderBatch != null && (this.effectChannel != value))
                {
                    OnInvalidateRenderBatch(this);
                }
                this.effectChannel = value; 
            }
        }
    }
}
